package com.qumap.item.event;

import com.google.gwt.event.shared.GwtEvent;
import com.qumap.item.ItemOnMap;

import java.util.Collection;
import java.util.LinkedList;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: Admin
 * Date: 10.05.11
 * Time: 19:50
 * To change this template use File | Settings | File Templates.
 */
public class ItemEvent extends GwtEvent<ItemEventHandler> {

	protected final List<ItemOnMap> items = new LinkedList<ItemOnMap>();

	private Type<ItemEventHandler> item_event_handler_type;

	public ItemEvent(Type<ItemEventHandler> item_event_handler_type) {
		this.item_event_handler_type = item_event_handler_type;
	}

	public void add(ItemOnMap selected_item) {
		items.add(selected_item);
	}

	public void add(Collection<ItemOnMap> item_collection) {
		items.addAll(item_collection);
	}

	public List<ItemOnMap> getSelectedItems() {
		return items;
	}

	public ItemOnMap getFirstItem() {
		return items.get(0);
	}

	public boolean isSingleItemEvent() {
		return items.size() == 1;
	}

	public boolean isEmpty() {
		return items.size() == 0;
	}


	@Override
	public Type<ItemEventHandler> getAssociatedType() {
		return item_event_handler_type;
	}

	@Override
	protected void dispatch(ItemEventHandler h) {
		h.onItemEvent(this);
	}
}
